package com.wanmait.meteor;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//配置类
@Configuration
public class DruidConfig {

    @Value("${druid.loginUsername}")
    private String username;
    @Value("${druid.loginPassword}")
    private String password;
    @Value("${druid.resetEnable}")
    private String resetEnable;
    //@Bean
    public ServletRegistrationBean druidServlet(){

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
               new StatViewServlet(),"/druid/*");
        //指定白名单
        //servletRegistrationBean.addInitParameter("allow","192.168.1.10,192.168.1.12");
        //指定黑名单
        //servletRegistrationBean.addInitParameter("deny","....");
        servletRegistrationBean.addInitParameter("loginUsername",username);
        servletRegistrationBean.addInitParameter("loginPassword",password);
        servletRegistrationBean.addInitParameter("resetEnable",resetEnable);
        return servletRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new WebStatFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.addInitParameter("exclusions","/druid/*,/static/*,*.js,*.css");
        return filterRegistrationBean;
    }






    //@Bean("questionTypeService")
    /*    @Bean
    public QuestionTypeService questionTypeService()
    {
        return new QuestionTypeServiceImpl();
    }*/
    /*     <bean id="questionTypeService" class="com.wanmait.bootdemo.service.impl.QuestionTypeServiceImpl"/>
*/
}
